#include "urltable.h"

UrlTable::UrlTable(QString dbTableName, QStringList dbTableColumn, QStringList dbTableColumnType,
                   QWidget *parent) :
    QWidget(parent)
{
    model = new QSqlTableModel();
    model->setTable(dbTableName);
    model->select();
    model->setEditStrategy(QSqlTableModel::OnFieldChange);


}

int UrlTable::rowCount(){
    return model->rowCount();
}

void UrlTable::addRow(DownloadTask *task){
    int rowCount = model->rowCount();
    model->insertRow(rowCount);

    QString s = task->rename();
    model->setData(model->index(rowCount, 0), task->rename());
    model->setData(model->index(rowCount, 1), task->path());
    model->setData(model->index(rowCount, 2), task->url().toString());
    model->submitAll();
}
/*
QString UrlTable::pathForTask(int taskIndex){
    return model->index(taskIndex, 0).data().toString();
}

QString UrlTable::urlForTask(int taskIndex){
    return model->index(taskIndex, 1).data().toString();
}
*/
